package com.xipu.yygh.user.controller;


import com.xipu.yygh.common.result.R;
import com.xipu.yygh.common.utils.HeadJwtHelper;
import com.xipu.yygh.model.user.UserInfo;
import com.xipu.yygh.user.service.UserInfoService;
import com.xipu.yygh.vo.user.LoginVo;
import com.xipu.yygh.vo.user.UserAuthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author gql
 * @since 2022-05-05
 */
@RestController
@RequestMapping("/api/user")
public class UserInfoController {
    /**
     * 用户信息
     */
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 获取用户id信息接口
     * @param request 请求
     * @return r
     */
    @GetMapping("auth/getUserInfo")
    public R getUserInfo(HttpServletRequest request) {
        UserInfo userInfo = this.userInfoService.getById(HeadJwtHelper.getUserId(request));
        return R.ok().data("userInfo", userInfo);
    }

    /**
     * 用户认证接口
     * @param userAuthVo 用户认证VO
     * @param request http请求
     * @return r
     */
    @PostMapping("auth/userAuth")
    public R userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
        this.userInfoService.userAuth(HeadJwtHelper.getUserId(request), userAuthVo);
        return R.ok();
    }

    /**
     * 用户登录
     * @param loginVo 登录vo
     * @return r
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo) {
        Map<String, Object> map = this.userInfoService.userLogin(loginVo);
        return R.ok().data(map);
    }
}

